<?php
 
my_component_load('testing' , false);
my_component_load('list_kalender' , false);
my_component_load('paging' , false);  
my_component_load('spd' );
$task = isset($_GET['task']) ? $_GET['task'] : "";  
$id = isset( $_GET['id'] ) ? $_GET['id']:  0; 
$sid = isset( $_GET['sid'] ) ? $_GET['sid']:  0; 
$karyawan_id = isset( $_GET['karyawan_id'] ) ? $_GET['karyawan_id']:  0; 
$key = isset( $_GET['key'] ) ? $_GET['key']:  "";
$kbulan = isset( $_GET['kbulan'] ) ? $_GET['kbulan']:  0;
$ktahun = isset( $_GET['ktahun'] ) ? $_GET['ktahun']:  "";
$kstatus = isset( $_GET['kstatus'] ) ? $_GET['kstatus']:  0;

$tipe_id = isset( $_GET['tipe_id'] ) ? $_GET['tipe_id']:  0; 

$modulname = "Personalia _BN_ Perjalanan Dinas";

if($_SERVER['REQUEST_METHOD'] == "POST" ):
	switch($task){ 
	case "edit_page":
		end($_POST); $valid_post=key($_POST); 
		$validatepost = spd_validate($id);
		if($validatepost){
			$errors = message_multi_error($validatepost);
			$content = $errors;
			$content .= form_spd($id,$valid_post,false);
		}else{
			if($valid_post=="submit"){
				submit_spd($id);
				$content = 'Updated' ;
			}else{
				$content = form_spd($id,$valid_post,true);	
			}		
		}
		generate_my_web($content, $pagename ,"plain.php");
		exit;				
		break; 
	case "edit_detail_page":
		$validatepost = spd_detail_validate($sid,$id);
		if($validatepost){
			$errors = message_multi_error($validatepost);
			$content = $errors;
			$content .= form_spd_detail($sid,$id);
			generate_my_web($content, $pagename ,"plain.php");
			exit;
		}else{	
			submit_spd_detail($sid,$id);
			generate_my_web('Updated', $pagename ,"plain.php");
			exit;
		}
		break; 		
	}

else: 
	if($task == "edit"){ 
		$pagename = ($id > 0 ) ? "Perubahan Data" : "Tambah Data";
		facebox_page('index.php?com=spd&task=edit_page&id='.$id , $pagename , 450	);
	}elseif($task == "edit_page"){
		$pagename = ($id > 0 ) ? "Perubahan Data" : "Tambah Data";
		$content = form_spd($id,'',false);
		generate_my_web($content, $pagename ,"plain.php");
		exit;	
	}elseif( $task =="delete"){
		remove_spd($id);
		my_direct('index.php?com='.$_GET['com']);

	}elseif( $task =="detail"){
		load_facebox_script();
		$pagename = $modulname;
		$content = list_detail($id);
	}elseif($task == "edit_detail"){ 
		$pagename = ($id > 0 ) ? "Perubahan Data" : "Tambah Data";
		facebox_page('index.php?com=spd&task=edit_detail_page&sid='.$sid.'&id='.$id , $pagename , 320	);
	}elseif($task == "edit_detail_page"){
		$pagename = ($id > 0 ) ? "Perubahan Data" : "Tambah Data";
		$content = form_spd_detail($sid,$id);
		generate_my_web($content, $pagename ,"plain.php");
		exit;
	}elseif($task == "plaincetak"){
		@ob_end_clean(); 
		echo'<pre>';
		echo print_plain($id);
		exit;		
	}else{ 
		$pagename = $modulname;
		load_facebox_script();
		$content =  list_spd($key,$kbulan,$ktahun,$kstatus); 
		
	}
endif;  
generate_my_web($content, $pagename );